//管理数据的文件
import handler from "./index"

//其他页面调用dispatch时就会执行下面code
let reducer = (state = {...handler.state}, action: { type: string}) => {
    //实现对象深拷贝
    let newState = JSON.parse(JSON.stringify(state))
    for(let key in handler.actionNames){
        if(action.type === handler.actionNames[key]){
            handler.actions[handler.actionNames[key]](newState, action)
            break
        }
    }
    return newState
}

export default reducer